package documents;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class DocumentLibrary {
	
	private ArrayList<Document> documents;
	private int IDcounter;
	private boolean activateStemmer;
	
	public DocumentLibrary(boolean activateStemmer) {
		documents = new ArrayList<Document>();
		IDcounter = 0;
		this.activateStemmer = activateStemmer;
	}
	
	public void addDocuments(String[] filenames) {
		for(String doc : filenames) {
			String text = readFile(doc);
			Document document = new Document(text, IDcounter, doc, activateStemmer);
			documents.add(document);
			IDcounter++;
		}
	}
	
	public ArrayList<Document> getDocuments() {
		return documents;
	}
	
	@SuppressWarnings("unused")
	private static String readFile(String filename)
	{
		String content = null;
		   File file = new File(filename); //for ex foo.txt
		   try {
		       FileReader reader = new FileReader(file);
		       char[] chars = new char[(int) file.length()];
		       reader.read(chars);
		       content = new String(chars);
		       reader.close();
		   } catch (IOException e) {
		       e.printStackTrace();
		   }
		   return content;
	}

	

}
